package com.example.callcenter.rabbitmq;

import com.example.callcenter.config.RabbitMQConfig; // 修正引用
import com.example.callcenter.dto.TaskMessageDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.MessageDeliveryMode;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 任务分发生产者（修正RabbitConfig→RabbitMQConfig引用）
 */
@Component
@Slf4j
public class TaskDistributeProducer {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    /**
     * 分发外呼任务给销售坐席
     */
    public void distributeTask(TaskMessageDTO message) {
        log.info("任务Task生产者开始发送短信消息: {}", message);
        rabbitTemplate.convertAndSend(
                RabbitMQConfig.TASK_EXCHANGE,  // 修正为RabbitMQConfig
                RabbitMQConfig.TASK_ROUTING_KEY,
                message,
                msg -> {
                    msg.getMessageProperties().setDeliveryMode(MessageDeliveryMode.PERSISTENT);
                    msg.getMessageProperties().setMessageId(message.getTaskId() + "_" + message.getCustomerId());
                    return msg;
                }
        );
        log.info("任务Task生产者短信消息发送完成");
    }
}